package com.example.world.servlet;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.example.world.dao.CityDAO;
import com.example.world.domain.City;

@WebServlet("/city")
public class CityServlet extends HttpServlet{
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException 
	{
		
		// 1. 获取用户提交的参数
		
		// 2. 调用DAO查询
		CityDAO cDAO = new CityDAO();
		List<City> list = null;
		try {
			list = cDAO.findAll();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// 3. 显示结果
		// 3.1 方式1 打印输出
		// 3.2 方式2 请求转发jsp
		req.setAttribute("list", list);
		req.getRequestDispatcher("city.jsp").forward(req, resp);
		
	}
}
